import Vue from "vue";
import Router from "vue-router";
import HelloWorld from "@/components/HelloWorld";

Vue.use(Router);

const demoRouter = [
  // 重定向首页
  {
    path: "*",
    name: "HelloWorld",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "登录",
    component: () => import("../view/login/index.vue"),
  },
  {
    path: "/register",
    name: "注册",
    component: () => import("../view/login/register.vue"),
  },
  {
    path: "/modify",
    name: "修改密码",
    component: () => import("../view/login/modify.vue"),
  },

  {
    path: "/excel",
    name: "上传文件",
    component: () => import("../view/excel"),
  },
  {
    path: "/index",
    name: "首页",
    component: () => import("../index"),
  },
  {
    path: "/next",
    name: "nextTick",
    component: () => import("../view/mydemo/nextTick.vue"),
  },
  {
    path: "/refs",
    name: "refs",
    component: () => import("../view/mydemo/refs.vue"),
  },
  {
    path: "/submit",
    name: "提交",
    component: () => import("../view/mydemo/submit.vue"),
  },
  {
    path: "/media",
    name: "媒体查询",
    component: () => import("../view/mydemo/media.vue"),
  },
  {
    path: "/list",
    name: "列表",
    component: () => import("../view/mydemo/list.vue"),
  },
  {
    path: "/tabList",
    name: "分页列表",
    component: () => import("../view/mydemo/tabList.vue"),
  },
  {
    path: "/detail",
    name: "详情展示",
    component: () => import("../view/mydemo/detail.vue"),
  },
  {
    path: "/object",
    name: "遍历对象",
    component: () => import("../view/mydemo/object.vue"),
  },
  {
    path: "/swiper",
    name: "轮播图",
    component: () => import("../view/mydemo/swiper.vue"),
  },
  {
    path: "/upload",
    name: "上传图片",
    component: () => import("../view/mydemo/upload.vue"),
  },
  {
    path: "/checkWord",
    name: "短信验证",
    component: () => import("../view/login/checkWord.vue"),
  },
  // {
  //   path: '/map',
  //   name: '地图',
  //   component: () => import('../view/map'),
  // },
];
localStorage.setItem("demoRouter", JSON.stringify(demoRouter));
const gameRouter = [
  {
    path: "/start",
    name: "开始",
    component: () => import("../view/prepare/start.vue"),
  },
  {
    path: "/site",
    name: "战斗界面",
    component: () => import("../view/battle/site.vue"),
  },
  {
    path: "/prepare",
    name: "准备",
    component: () => import("../view/prepare/index.vue"),
  },
  {
    path: "/talent",
    name: "天赋",
    component: () => import("../view/prepare/talent.vue"),
  },
  {
    path: "/elements",
    name: "灵根",
    component: () => import("../view/prepare/elements.vue"),
  },
  {
    path: "/pray",
    name: "祈愿",
    component: () => import("../view/prepare/pray.vue"),
  },
  {
    path: "/test",
    name: "测试",
    component: () => import("../view/test.vue"),
  },
  {
    path: "/atlas",
    name: "图鉴",
    component: () => import("../view/atlas"),
  },
  {
    path: "/canvas",
    name: "绘图",
    component: () => import("../view/canvas"),
  },
  {
    path: "/chessboard",
    name: "棋盘",
    component: () => import("../view/canvas/chessboard"),
  },
  {
    path: "/monopoly",
    name: "大富翁",
    meta: {
      showNav: false,
    },
    component: () => import("../view/mydemo/monopoly"),
  },
  {
    path: "/newMonpoly",
    name: "大富翁",
    meta: {
      showNav: false,
    },
    component: () => import("../view/mydemo/newMonpoly"),
  },
  {
    path: "/monopoly3",
    name: "大富翁3",
    meta: {
      showNav: false,
    },
    component: () => import("../view/mydemo/monopoly3"),
  },
  {
    path: "/monopoly4",
    name: "大富翁4",
    meta: {
      showNav: false,
    },
    component: () => import("../view/mydemo/monopoly4"),
  },
  {
    path: "/battle",
    name: "战斗",
    meta: {
      showNav: false,
    },
    component: () => import("../view/mydemo/battle"),
  },
];
localStorage.setItem("gameRouter", JSON.stringify(gameRouter));
const routes = [];
routes.push(...gameRouter);
routes.push(...demoRouter);
const router = new Router({ routes });
router.beforeEach((to, from, next) => {
  if (to.path == "/login") return next();
  const tokenstr = window.localStorage.getItem("token");
  if (!tokenstr) return next("/login"); //token校验
  document.title = to.name;
  next();
});
export default () => {
  // return {gameRouter,demoRouter,router}
  return router;
};
// export {
//   router
// }
